<?php
header('content-type:text/html;charset=utf-8');
$subject="2016-05-01";
$pattern='#(\d{4})-(\d{2})-(\d{2})#';
// preg_match_all($pattern, $subject,$matches);
// print_r($matches);
$replacement='$1年$2月$3日';
echo preg_replace($pattern,$replacement,$subject);
echo '<hr/>';
$subject='This is of King Show Time~Welcome To Maizi!';
$patterns=array(
  '#king#i',
   '#maizi#i'
);
$replacement=array(
    '何山老师',
    '麦子学院'
);
echo preg_replace($patterns, $replacement, $subject);
echo '<hr/>';
//删除空白符
$subject='a   b
    c
    d
    ';
$subject=preg_replace('#\s\s+#','',$subject);
echo $subject;
echo '<hr/>';

$subject='a=1;b=2;c=3';
$callback=function($match){
    return $match[0]*5;
};
$subject=preg_replace_callback('#(\d+)#', $callback, $subject);
echo $subject;
echo '<hr/>';
$subject='this is a test';
$subject=preg_replace_callback('#(\w+)#', function($match){return strtoupper($match[0]);}, $subject);
echo $subject;
























